package com.jvyou.pms.controller;



import com.jvyou.common.response.R;
import com.jvyou.pms.domain.dto.SysDictTypeDto;
import com.jvyou.pms.domain.entity.SysDictType;
import com.jvyou.pms.service.SysDictTypeService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import java.util.List;
import com.jvyou.common.response.BizResponseCode;
import com.jvyou.common.exception.BizException;
import com.jvyou.common.response.Page;


/**
 * 字典类型表(SysDictType)表控制层
 *
 * @author 橘柚
 * @since 2025-06-29 01:57:29
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysDictType")
public class SysDictTypeController  {
    
    private final SysDictTypeService sysDictTypeService;
    
     /**
     * 查询sysDictType列表
     *
     * @param dto 查询参数
     * @return sysDictType 列表
     */
    @GetMapping("/list")
    @SaCheckPermission("sys:sysDictType:list")
    public R<List<SysDictType>> list(@ModelAttribute SysDictTypeDto dto) {
        return R.ok(sysDictTypeService.listSysDictType(dto));
    }

     /**
     * 分页查询sysDictType列表
     *
     * @param dto 查询参数
     * @return sysDictType 分页列表
     */
    @GetMapping("/page")
    @SaCheckPermission("sys:sysDictType:page")
    public R<Page<SysDictType>> page(@ModelAttribute SysDictTypeDto dto) {
        return R.ok(sysDictTypeService.pageSysDictType(dto));
    }

    /**
     * 通过主键查询 sysDictType 单条
     *
     * @param id sysDictType 主键
     * @return sysDictType 单条数据
     */
    @GetMapping("/{id}")
    @SaCheckPermission("sys:sysDictType:get")
    public R<SysDictType> selectOne(@PathVariable("id") Long id) {
        return R.ok(sysDictTypeService.getById(id));
    }

    /**
     * 新增 sysDictType
     *
     * @param sysDictType 实体对象
     * @return 新增sysDictType结果
     */
    @PostMapping
    @SaCheckPermission("sys:sysDictType:insert")
    public R<SysDictType> insert(@RequestBody SysDictType sysDictType) {
        boolean success = sysDictTypeService.save(sysDictType);
        if (!success) {  
		    throw new BizException(BizResponseCode.ERR_12001);  
		}  
		return R.ok(sysDictType);
    }
    
     /**
     * 修改sysDictType
     *
     * @param sysDictType 实体对象
     * @return 修改sysDictType结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("sys:sysDictType:update")
    public R<SysDictType> updateById(@RequestBody SysDictType sysDictType) {
        boolean success = sysDictTypeService.updateById(sysDictType);
        if (!success) {  
		    throw new BizException(BizResponseCode.ERR_12003);  
		}
		return R.ok(sysDictType);
    }
    

    /**
     * 删除sysDictType数据
     *
     * @param id sysDictType主键
     * @return 删除sysDictType结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("sys:sysDictType:delete")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        boolean success = sysDictTypeService.removeById(id);
		if (!success) {  
		    throw new BizException(BizResponseCode.ERR_12002);  
		}  
		return R.ok(Boolean.TRUE);
    }
    
}

